package com.yitiao.data_algorithms.leetcode.editor.cn;

class Xoh6Oh{
    // 2023-02-22 18:10:16
    public static void main(String[] args) {
        Solution solution = new Xoh6Oh().new Solution();
    }
    
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int divide(int a, int b) {
//        if (a>Math.pow(2,31)-1)a= (int) (Math.pow(2,31)-1);
//        if (b>Math.pow(2,31)-1)b= (int) (Math.pow(2,31)-1);
//
//        if (a<-Math.pow(2,31))a= (int) -(Math.pow(2,31));
//        if (b<-Math.pow(2,31))b= (int) -(Math.pow(2,31));

        long c=Math.abs((long)a);
        long d=Math.abs((long)b);
        long sum=0;
        while (c>=d){
            c=c-d;
            sum++;
        }
        if ((a>0&&b>0)||(a<0&&b<0)){
            if (sum>Math.pow(2,31)-1){
                sum = (int) (Math.pow(2,31)-1);
            }
            return (int) sum;
        }
//        else {
//            if (sum==Math.pow(2,31)){
//                return -2147483648;
//            }
//        }
        return (int) -sum;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}